package streaming

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * 从文件系统（local/hdfs等）中统计
  * 文件必须是move过来的
  */
object FileWorldCount {

  def main(args: Array[String]): Unit = {
    val sc = new SparkConf().setMaster("local[*]").setAppName("FileWorldCount")

    val ssc = new StreamingContext(sc,Seconds(5))

    val lines = ssc.textFileStream("file:///Users/stephen/Desktop/test/")

    val result = lines.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_)

    result.print()

    ssc.start()

    ssc.awaitTermination()
  }

}
